package com.example.teatea.controller;

import com.example.teatea.FindPswApp;
import com.example.teatea.RegisterApp;
import com.example.teatea.SeatApp;
import com.example.teatea.SeatMoreApp;
import com.example.teatea.dao.CheckLogin;
import com.example.teatea.dao.GetStaff;
import com.example.teatea.project.Staff;
import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javax.swing.*;

public class LoginController {
    public Button loginBt;
    public Button fogetBt;
    public TextField phone;
    public PasswordField psw;
    public Button registerBt;
    public static Staff s;

    public void toLogin(ActionEvent actionEvent) throws Exception {
        Staff staff = new Staff();
        staff.setsPhone(phone.getText());
        if(phone.getText().equals("")){
            JOptionPane.showMessageDialog(null, "手机号不能为空！", "提示", JOptionPane.ERROR_MESSAGE);
        }else if(psw.getText().equals("")){
            JOptionPane.showMessageDialog(null, "密码不能为空！", "提示", JOptionPane.ERROR_MESSAGE);
        }else if(!new CheckLogin().checkLogin(staff,psw.getText())){
            JOptionPane.showMessageDialog(null,"手机号或密码错误！","提示",JOptionPane.ERROR_MESSAGE);
        }else{
            JOptionPane.showMessageDialog(null, "登陆成功", "提示", JOptionPane.PLAIN_MESSAGE);
            s = new GetStaff().getStaff(staff);
            Stage stage = (Stage) loginBt.getScene().getWindow();
            stage.close();
            if(s.getsType().equals("0")){
                SeatApp seatApp = new SeatApp();
                seatApp.start(stage);
            }else{
                SeatMoreApp seatMoreApp = new SeatMoreApp();
                seatMoreApp.start(stage);
            }
        }
    }

    public void toFoget(ActionEvent actionEvent) throws Exception {
        Stage stage = (Stage) fogetBt.getScene().getWindow();
        stage.close();
        FindPswApp findPswApp = new FindPswApp();
        findPswApp.start(stage);
    }

    public void toRegister(ActionEvent actionEvent) throws Exception {
        Stage stage = (Stage) registerBt.getScene().getWindow();
        stage.close();
        RegisterApp registerApp = new RegisterApp();
        registerApp.start(stage);
    }
}
